<?php
require("includes/basic.php");
$task=$_POST['taskid'];
$status=$_POST['status'];
$statusdesc=addslashes($_POST['status-desc']);
$estimatedtime=$_POST['etime'];
$priority=$_POST['priority'];
$creator=$userId;
$sql=mysql_query("update task_status set task_status=$status, status_description=$statusdesc, task_modified_on=sysdate(), task_modified_by=$creator where task_id = $task");
if(isset($_POST['submit']) && $_FILES['uploadedfile']['size'] > 0)
	{

		$fileName = $_FILES['uploadedfile']['name'];
		$tmpName = $_FILES['uploadedfile']['tmp_name'];
		$fileSize = $_FILES['uploadedfile']['size'];
		$fileType = $_FILES['uploadedfile']['type'];

		$fp      = fopen($tmpName, 'r');
		$content = fread($fp, filesize($tmpName));
		$content = addslashes($content);
		fclose($fp);

		if(!get_magic_quotes_gpc())
		{
			$fileName = addslashes($fileName);
		}

		$query = "INSERT INTO task_doc (name, size, type, content, task_id, uploaded_on, uploaded_by) VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$taskid', sysdate( ), '$creator')";

		mysql_query($query) or die('Error, query failed'); 

		$filePath = $target_path . $fileName;

		//$result = move_uploaded_file($tmpName, $filePath);
		//if (!$result) {
		//echo "Error uploading file";
		//exit;
		//}
		echo "uploaded";
	}
$project=mysql_query("select * from task_master where task_id=$task");
$projectr=mysql_fetch_array($project);
extract($projectr);
$projectid=$projectr['project_id'];
$title=$projectr['task_title'];
$desc=$projectr['task_description'];
$phase=$projectr['phase_id'];
$module=$projectr['module_id'];
$creator=$userId;
/* Rework and Reassign */
if($status=='reopened' || $status=='reassign')
{
	$newtask=mysql_query("insert into task_master (`project_id`,`task_priority`,`task_title`,`task_description`,`phase_id`,`	module_id`,`task_created_on`,`task_created_by`,`estimated_time`) values ('$projectid','$priority','$title','$desc','$phase','$module',sysdate(),'$creator','$time')");
	$ntask=mysql_query("select * from task_master where project_id=$projectid order by task_id desc limit 1");
	$ntaskr=mysql_fetch_array($ntask);
	$ntaskid=$ntaskr['task_id'];
	$updatereferto=mysql_query('update task_status set task_reference_id=$ntaskid');
	/*Rework*/
	if($status=='reopened')
	{
		$getresource=mysql_query("select * from task_assigned_to where task_id=$task");
		if(mysql_num_rows($getresource))
		{
		$getresourcer=mysql_fetch_array($getresource);
		extract($getresourcer);
		$assignedto=$getresourcer['task_assigned_to'];		
		}
	}
	/* Reassign */
	if($status=='reassign')
	{
		$assignedto=$_POST['assign'];		
	}
	$newresource=mysql_query("insert into task_assigned_to (`task_id`,`	task_assigned_to`,`task_assigned_on`,`task_assigned_by`) values (`$ntaskid`,`$assignedto`,sysdate(),'$creator')");
	$newtaskstatus=mysql_query("insert into task_status (`task_id`,`task_status`,`task_created_on`,`task_created_by`) values ('$ntaskid','1',sysdate(),'$creator')");
}
header("location:view-task.php?pid=0000000001&sid=3&mid=1");
?>